package com.beone.admin.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.beone.admin.entity.Version;
import com.beone.admin.mapper.VersionMapper;
import com.beone.admin.service.VersionService;
import com.base.SuperServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import com.beone.admin.utils.PaginationGatagridTable;
import com.beone.admin.utils.ServiceUtils;

import java.util.List;

/**
 * @Title 版本表 服务实现类
 * @Author 秦波
 * @Version 1.0 on 2019-05-11
 * @Copyright 贝旺科权
 */
@Service
public class VersionServiceImpl extends SuperServiceImpl<VersionMapper, Version> implements VersionService {

    /**
    * 分页显示版本表列表
    * @param entity
    * @param currPage  当前页码
    * @param pageSize  每页显示记录数
    * @return
    */
    public PaginationGatagridTable getVersionPagination(Version entity, int currPage, int pageSize){
        EntityWrapper<Version> ew = new EntityWrapper<Version>();
        Page<Version> page = new Page<Version>(currPage,pageSize);
        List<Version> rows = baseMapper.selectPage(page, ew);
        return ServiceUtils.createGatagridTableJson(page,rows);
    }

    @Override
    public Version getLatestVersion() {
        EntityWrapper<Version> ew = new EntityWrapper<Version>();
        Page<Version> page = new Page<Version>(1,1);
        ew.orderBy("version", false);
        List<Version> rows = baseMapper.selectPage(page, ew);
        return CollectionUtils.isEmpty(rows) ? null : rows.get(0);
    }
}
